package com.binsoft.ndtta;

public class Encryptor
{
	@SuppressWarnings("unused")
	private static final String TAG = "Encryptor";

	public static byte[] encrypt( byte[] input ) 
	{
		return encrypt( input, Constants.DECRYPTOR );
	}
	
	public static byte[] encrypt( byte[] input, byte[] key ) 
	{
		byte[] encrypted = new byte[ input.length ];
		
		if ( input != null )
		{
			int keyIndex = 0;
			
			for (int index = 0 ; index < input.length ; ++index )
			{
				encrypted[ index ] = (byte)(input[ index ] + key[keyIndex]);
				
				keyIndex = ( keyIndex++ % key.length );
			}
		}
		
        return encrypted;
	}
	
	public static byte[] decrypt( byte[] input )
	{
		return decrypt( input, Constants.DECRYPTOR );
	}
	
	public static byte[] decrypt( byte[] input, byte[] key )
	{
		byte[] decrypted = null;
		
		if ( null != input )
		{
			decrypted = new byte[ input.length ];
			int keyIndex = 0;
			
			for (int index = 0 ; index < input.length ; ++index )
			{
				decrypted[ index ] = (byte)(input[ index ] - key[keyIndex]);
				
				keyIndex = ( keyIndex++ % key.length );
			}
		}
		
        return decrypted;
	}
}
